import App from './App'
import router from './router'
import store from './repo/store/store'
import VueMeta from 'vue-meta-info'
import NProgress from 'nprogress'
import 'amfe-flexible'
import 'swiper/css/swiper.css'
import 'mint-ui/lib/style.css'
import 'element-ui/lib/theme-chalk/index.css'
import '../static/font/iconfont.css'
import 'vant/lib/button/style'
import 'vant/lib/index.css'

import {beforeEachRouter} from './biz/RouterBiz'
import {push, replace} from './router/util'

import {realImgCallback} from './utils/directive/real_img'
import smoothscroll from 'smoothscroll-polyfill'

import BuyMemberPopup from '@/components/BuyMemberPopup/BuyMemberPopup';

smoothscroll.polyfill();

NProgress.configure({
  'showSpinner': true,
});


Vue.prototype.$moment = moment;//赋值使用
Vue.prototype.$NProgress = NProgress;
Vue.use(VueMeta);

Vue.prototype.$axios = axios;
Vue.prototype.$_router = {
  push, replace
};
Vue.prototype.$buyMemberPopup = BuyMemberPopup;
axios.defaults.baseURL = process.env.NODE_ENV === 'production' ? '/api' : '/api';
Vue.config.productionTip = false;
Vue.config.devtools = process.env.NODE_ENV !== 'production';
Vue.directive('real-img', realImgCallback);


router.beforeEach((to, from, next) => {
  window.document.title = to.meta.title == undefined ? '在线教育' : to.meta.title;
  NProgress.start();

  //执行跳转逻辑
  try {
    beforeEachRouter(to, from, next)
  } catch (e) {
    next({'name': 'auth-failed'})
  }

});


router.afterEach((to) => {
  NProgress.done();
  window.scroll({top: 0, left: 0, behavior: 'smooth'});
});

new Vue({
  el: '#app',
  router,
  store,
  components: {App},
  template: '<App/>'
});
